<template>
	<div id="app">
		<el-container>
			<el-header><!-- 头部 -->
				<div class="header">
					<span>图书后台管理系统</span>
				</div>
				<el-button type="danger" @click="logout">退出</el-button>
			</el-header>
			<el-container>
				<el-aside :width="isCollapse ? '64px' : '200px'"><!-- 侧边栏 -->
				<div class="toggle-button" @click="toggle()">
					|||
				</div>
					<el-menu background-color="#333744" text-color="#fff" unique-opened='true'
					 :collapse="isCollapse" :collapse-transition="false" router :default-active="NavState">  <!-- 一级标题 -->
						<el-submenu :index="item.id+''" v-for="item in menuList">
							<template slot="title">
								<i :class="iconsObj[item.id]"></i>
								<span>{{item.suthName}}</span>
							</template>
							<el-menu-item :index="ite.path" v-for="ite in item.children" @click="saveNavState(ite.path+'')"> <!-- 二级标题 -->
								<i class="el-icon-menu"></i>
								<span>{{ite.suthName}}</span>
							</el-menu-item>
						</el-submenu>
					</el-menu>
				</el-aside>
				<el-container>  <!-- 主界面 -->
					<el-main>
						<router-view></router-view>
					</el-main>
				</el-container>
			</el-container>
		</el-container>

	</div>
</template>

<script>
	export default {
		data() {
			return {
				//左侧菜单数据
				menuList:[],
				iconsObj:{
					'1':'iconfont icon-team',
					'2':'iconfont icon-home',
					'3':'iconfont icon-shopping',
					'4':'iconfont icon-Dollar-circle-fill',
					'5':'iconfont icon-desktop'
				},
				isCollapse:false,
				NavState:''
			}
		},
		methods: {
			logout() {
				window.sessionStorage.clear();
				this.$router.push('/Login');
				this.$message.success('退出成功');
			},
			getMenuList(){
				this.$http.get("menus.json").then(res=>{
					console.log(res.data);
					const date=res.data;
					console.log(date);
					console.log(date.meta.status);
					if(date.meta.status!==200)return this.$message.error("获取菜单失败");
					this.menuList=date.data;
					console.log(date.data);
				})
				
			},
			toggle(){
				
				this.isCollapse=!this.isCollapse;
			},
			saveNavState(data){
				console.log(data);
				window.sessionStorage.setItem('data',data);
				this.NavState=data;
			}
			
		},
		created() {
			this.getMenuList();
			this.NavState=window.sessionStorage.getItem('data');
		}
	};
</script>

<style scoped>
	.el-header {
		background-color: #373d41;
		display: flex;
		justify-content: space-between;
		padding-left: 0;
		align-items: center;
		color: #FFFDEF;
		font-size: 20px;

		>div {
			display: flex;
			align-items: center;
		}
	}

	.el-aside {
		background-color: #333744;
		
	}
	.el-menu{
		border-right: none;
	}

	.el-main {
		background-color: #eaedf1;
	}

	.el-container {
		height: 100%;
	}
	.iconfont{
		margin-right: 10px;
	}
	.toggle-button{
		width: 100%;
		background-color: #4A5064;
		font-size: 10px;
		line-height: 24px;
		color: white;
		text-align: center;
		letter-spacing: 0.2em;  /* 间距 */
		cursor: pointer;
	}
</style>
